from flask import Flask, jsonify, request, render_template
import pymysql
app = Flask(__name__)
@app.route('/')
def index():
    return render_template('flask1.html', title='Welcome Page', name='John Doe')

@app.route('/log', methods=['POST'])
def log():
    log=False;
    name = request.form.get('name')
    conn = pymysql.Connect(
        host="121.196.247.129",
        user="hospital",
        password="xz4XmwLkaxkaM6Dd",
        database="hospital",
        port=3306,  # 端口号，默认即3306
        charset="utf8"
    )
    cursor = conn.cursor(cursor=pymysql.cursors.DictCursor)  # 以字典的形式取数据
    db = 'user_info'
    sql = f"SELECT * FROM {db}"
    cursor.execute(sql)
    # 只要不涉及数据的更改，可以不需要调用commit()方法提交更改
    result = cursor.fetchall()
    FInalname="empty"
    FInalemail = "empty"
    for row in result:
        if (row['name'] == name):
            FInalname=name
            FInalemail=row['age']
            log=True
            break

    cursor.close()
    conn.close()
    return render_template('logging.html', statu=log)
    #return render_template('flask1.html', title=FInalemail, name=FInalname)
@app.route('/enroll', methods=['POST'])
def enroll():
    return render_template('logging.html', statu=log)

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=8080)
